package threaddemo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class SafeCollectionIteration {

    public static void main(String[] args) {
        List<String> wordList = Collections.synchronizedList(new ArrayList<>());

        wordList.add("A");
        wordList.add("B");
        wordList.add("C");

        synchronized (wordList) {
            Iterator iterator = wordList.iterator();
            while (iterator.hasNext()) {
                String s = (String) iterator.next();
                System.out.println(s);
            }
        }
    }
}
